/*
 * MIT LICENSE
 */
package br.com.zuq.geocode;

import java.util.List;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

public class LatLongUtil {

    // Attributes --------------------------------------------------------------
    // Static ------------------------------------------------------------------
    /**
     * Reads a file containing latitude and longitudes separated by comma. Ex.:
     * <p>
     * -9.67433,-35.761292
     * -9.674252,-35.761356
     * -9.674193,-35.761406
     * ...
     * @param path the path of the file to parse
     * @return a list of <code>LatLong</code>
     */
    public static List<LatLong> parseFile(String path) {
        List<LatLong> points = new ArrayList<LatLong>();
        BufferedReader reader = null;
        try {


            String linha;

            try {
                reader = new BufferedReader(
                        new FileReader(path));

                while ((linha = reader.readLine()) != null) {
                    if (!linha.startsWith("#")) {
                        String[] latLng = linha.split(",");
                        points.add(new LatLong(
                                Double.parseDouble(latLng[0]),
                                Double.parseDouble(latLng[1])));
                    }
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        } finally {
            try {
                reader.close();
            } catch (IOException ex) {
                // Do nothing
            }
        }

        return points;

    }
    // Overwriting of superclass's methods -------------------------------------
}
